package com.chengyu.core.controller;


import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.service.AssistService;
import com.chengyu.core.service.system.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 援助 前端控制器
 * </p>
 *
 * @author wenlj
 * @since 2023-10-29
 */
@Api(tags = "援助领养", description = "MemberAddressController")
@Controller
@RequestMapping("/app")
public class AppController extends UserBaseController {


    @Autowired
    private ConfigService configService;

    @ApiOperation(value = "版本检测")
    @RequestMapping(value = "/updatever", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "versionCode", value = "当前版本", dataType = "string")
    })
    public CommonResult<Map<String, Object>> updatever(String versionCode) {


        String version;
        String versionName;
        String versionCodeLast;
        String updateType ="";//默认不更新
        Boolean forceUpdate = false;

        String versionInfo="版本信息\r\n1. ......\r\n2. ......";




        Map<String, String> configmap = configService.getAllConfigValueMapByNoCache();
        System.out.println(configmap);
//        configmap.get("android_version");
//        configmap.get("android_update_content");
//        configmap.get("ios_version");

        version  = configmap.get("android_version");
        versionInfo  = configmap.get("android_update_content");
        String downloadUrl =configmap.get("android_app_download_url");





        versionName = version;

        versionCodeLast =  versionName.replace(".", "");



        if(versionCode==null){
            versionCode = "100";
        }
        if(!versionCode.equals(versionCodeLast)){
            updateType = "solicit";
        }



        Map<String, Object> map = new HashMap<>();
        map.put("version",versionName);
        map.put("path",downloadUrl);
        map.put("upgradeUrl","");
        map.put("versionCode",versionCodeLast);
        map.put("versionName",versionName);
        map.put("versionInfo",versionInfo);
        map.put("updateType",updateType);
        map.put("downloadUrl",downloadUrl);
        map.put("forceUpdate",forceUpdate);



        return CommonResult.success(map);

//             versionCode     | y        | int       | 版本号        |
//             * | versionName     | y        | String    | 版本名称      |
//             * | versionInfo     | y        | String    | 版本信息      |
//             * | updateType      | y        | String    | forcibly = 强制更新, solicit = 弹窗确认更新, silent = 静默更新 |
//             * | downloadUrl     | y        | String    | 版本下载链接（IOS安装包更新请放跳转store应用商店链接,安卓apk和wgt文件放文件下载链接）  |



    }






}

